
#include <iostream>
#include "cmdhelper.h"
using namespace std;

int main(int argc, char* argv[]) {

	/*argc -= (argc > 0);
	argv += (argc > 0); // skip program name argv[0] if present*/
	option::Stats stats(usage, argc, argv);
	option::Option* options = new option::Option[stats.options_max];
	option::Option* buffer  = new option::Option[stats.buffer_max];
	option::Parser parse(usage, argc, argv, options, buffer);

	if (parse.error()) {
		return 1;
	}

	if (options[HELP] || argc == 0) {
		int columns = getenv("COLUMNS") ? atoi(getenv("COLUMNS")) : 80;
		option::printUsage(fwrite, stdout, usage, columns);
		return 0;
	}

	if (!(options[PROGRAM] and options[INFILE] and options[FORMAT])) {
		fprintf(stdout, "Illegal number of arguments\n\n", "");
		return 0;
	} else {

		if (!PROGRAMTYPES.count(options[PROGRAM].arg)) {
			fprintf(stdout, "Invalid program type: %s\n\n", options[PROGRAM].arg);
			return 0;
		}
		if (!FILETYPES.count(options[FORMAT].arg)) {
			fprintf(stdout, "Invalid filetype: %s\n\n", options[FORMAT].arg);
			return 0;
		}
	}
	/*for (int i = 0; i < parse.optionsCount(); ++i) {
		option::Option& opt = buffer[i];
		fprintf(stdout, "Argument #%d is ", i);
		switch (opt.index()) {
		case HELP:
			// not possible, because handled further above and exits the program
		case OPTIONAL:
			if (opt.arg)
				fprintf(stdout, "--optional with optional argument '%s'\n",
						opt.arg);
			else
				fprintf(stdout, "--optional without the optional argument\n");
			break;
		case REQUIRED:
			fprintf(stdout, "--required with argument '%s'\n", opt.arg);
			break;
		case NUMERIC:
			fprintf(stdout, "--numeric with argument '%s'\n", opt.arg);
			break;
		case NONEMPTY:
			fprintf(stdout, "--nonempty with argument '%s'\n", opt.arg);
			break;
		case INFILE:
			fprintf(stdout, "--inputfile with argument '%s'\n", opt.arg);
			break;
		case PROGRAM:
			fprintf(stdout, "--program with argument '%s'\n", opt.arg);
			break;
		case UNKNOWN:
			// not possible because Arg::Unknown returns ARG_ILLEGAL
			// which aborts the parse with an error
			break;
		}
	}

	for (int i = 0; i < parse.nonOptionsCount(); ++i)
		fprintf(stdout, "Non-option argument #%d is %s\n", i,
				parse.nonOption(i));*/
	printf("All params valid: \n", "");
	cerr << "#num args" << parse.optionsCount() << endl;
	cerr  << "-p " << options[PROGRAM].arg <<
			"\n-if "<< options[INFILE].arg <<
			"\n-ff " << options[FORMAT].arg << endl;


	return 0;
}
